package br.com.agiledev.webscrum.eao;

import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import br.com.agiledev.webscrum.entity.ItemRelease;
import br.com.agiledev.webscrum.entity.Product;
import br.com.agiledev.webscrum.entity.Release;

@Name("releaseEAO")
@Scope(ScopeType.APPLICATION)
@AutoCreate
public class ReleaseEAO extends BaseEAO<Release> {

    /**
     * Recupera as releases associadas ao produto.
     * 
     * @param product
     *            produto.
     * @return lista de release.
     */
    @SuppressWarnings("unchecked")
    public List<Release> findByProduct(Product product) {
	return getEntityManager().createNamedQuery("Release.byProduct").setParameter("product", product)
		.getResultList();
    }

    @SuppressWarnings("unchecked")
    public List<ItemRelease> itensReleaseSomente(Long oid) {
	
	return getEntityManager()
		.createQuery(
			"select ir from ItemRelease ir where ir.release.id = :oid and ir.item not in (select obj.item from ItemSprint obj where obj.sprint.release.id = :oid) order by ir.item.prioridade desc")
		.setParameter("oid", oid).getResultList();
    }

}